home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / diverses / cexpress / screen / wrtcntrb.asm < prev    next >
Encoding:
Assembly Source File  |  1989-05-03  |  2.9 KB  |  97 lines

  1. ;void  write_center_b(strg,col,row,length,ln_color,strg_color);
  2. ;  unsigned char  *strg,col,row,length,ln_color,strg_color;
  3.  
  4.     EXTRN  _memory_model:byte
  5.     EXTRN  _video_page:byte
  6.     EXTRN  _error_code:byte
  7.  
  8. _TEXT    SEGMENT BYTE PUBLIC 'CODE'
  9.     ASSUME CS:_TEXT
  10.     PUBLIC _write_center_b
  11. _write_center_b proc near
  12.     push bp            ;
  13.     mov  bp,sp        ;set stack frame
  14.     push di            ;
  15.     push si            ;
  16.     cmp  _memory_model,0    ;near or far?
  17.     jle  begin        ;jump if near
  18.     inc  bp            ;else add 2 to BP
  19.     inc  bp            ;
  20. begin:    mov  bh,_video_page    ;set video page
  21.     push ds            ;save DS
  22.     cmp  _memory_model,2    ;data near or far?
  23.     jb   L0            ;jump if near
  24.     lds  si,dword ptr[bp+4] ;DS:SI pts to Strg
  25.     inc  bp            ;add 2 to BP since dword ptr    
  26.     inc  bp            ;
  27.     jmp  short L00        ;
  28. L0:    mov  si,[bp+4]        ;near case
  29. L00:    sub  dx,dx        ;DX counts string length
  30.     push si            ;keep initial pointer position
  31. L000:    cmp  byte ptr[si],0    ;end of string?
  32.     je   L0000        ;jump if so
  33.     inc  si            ;inc ptr 
  34.     inc  dx            ;inc counter
  35.     jmp  short L000        ;loop till end
  36. L0000:    pop  si            ;restore ptr
  37.     sub  cx,cx        ;
  38.     mov  cl,[bp+10]        ;line length in CX
  39.     mov  byte ptr[bp+4],0    ;0 = no error
  40.     sub  cx,dx        ;line len minus strg len
  41.     cmp  cx,0        ;check that 0 or more
  42.     jge  L1            ;jump ahead if so
  43.     mov  byte ptr[bp+4],1    ;1 = Length shorter than Strg
  44.     sub  cx,cx        ;else remainder is 0
  45. L1:    mov  ax,cx        ;copy in AX
  46.     shr  cx,1        ;now one half in CX
  47.     sub  ax,cx        ;remainder in AX
  48.     push ax            ;push remainder for later
  49.     push dx            ;push strg len for later
  50.     mov  dl,[bp+6]        ;Col in DL
  51.     dec  dl            ;count from 0
  52.     mov  dh,[bp+8]        ;Row in DH
  53.     dec  dh            ;count from 0
  54.     mov  ah,2        ;function to set cursor
  55.     int  10h        ;set cursor to line
  56.     mov  bl,[bp+12]        ;line attribute in BL
  57.     jcxz L2            ;jmp if no spaces on left
  58.     mov  al,32        ;space char
  59.     mov  ah,9        ;BIOS func to write char
  60.     int  10h        ;draw spaces on left
  61.     add  dl,cl        ;rightward cursor offset
  62.     mov  ah,2        ;function to set cursor
  63.     int  10h        ;reset the cursor
  64. L2:    pop  di            ;string length counter
  65.     or   di,di        ;null string?
  66.     jz   L4            ;jump ahead if so
  67.     mov  cx,1        ;print 1 char each time
  68.     mov  bl,[bp+14]        ;string attribute in BL
  69. L3:    mov  ah,9        ;function to write char
  70.     mov  al,[si]        ;get char from string
  71.     inc  si            ;inc ptr for next time
  72.     int  10h        ;write the string
  73.     mov  ah,2        ;function to set cursor
  74.     inc  dl            ;forward col count
  75.     int  10h        ;forward the cursor
  76.     dec  di            ;dec character counter
  77.     jnz  L3            ;loop if not finished
  78. L4:    pop  cx            ;right end spaces
  79.     jcxz L5            ;quit if no spc on right
  80.     mov  al,32        ;space character
  81.     mov  bl,[bp+12]        ;line attribute in BL
  82.     mov  ah,9        ;restore function number
  83.     int  10h        ;draw spaces on right
  84. L5:    pop  ds            ;restore DS
  85.     mov  al,[bp+4]        ;fetch _error_code
  86.     mov  _error_code,al    ;set it
  87.     pop  si            ;
  88.     pop  di            ;
  89.     pop  bp            ;
  90.     cmp  _memory_model,0    ;quit
  91.     jle  quit        ;
  92.     db   0CBh        ;RET far
  93. quit:    ret            ;RET near
  94. _write_center_b endp
  95. _TEXT    ENDS
  96.     END
  97.